home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
ISSUE18
/
SURVIVE
/
PASS1.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-12-09
|
3KB
|
103 lines
unit Pass1;
interface
uses
SysUtils, DB, DBTables;
function ChangePassword(iAliasName : PChar;
iServerName : PChar;
iDatabaseName : PChar;
iUserName : PChar;
iOldPassword : PChar;
iNewPassword : PChar;
var oErrMsg : PChar): Word; export;
implementation
uses
PassInt;
type
ESamePassword = class(Exception);
EErrorChangingPassword = class(Exception);
function ChangePassword;
var
TempDatabase: TDatabase;
TempQuery: TQuery;
begin
Result := cpSuccess;
StrPCopy(oErrMsg, '');
try
{ Validate the new password }
if StrIComp(iOldPassword, iNewPassword) = 0 then
raise ESamePassword.Create('');
{ Create a TDatabase structure to connect with }
TempDatabase := TDatabase.Create(nil);
try
with TempDatabase do
begin
AliasName := StrPas(iAliasName);
DatabaseName := 'PasswordChangeDB';
if Assigned(iServerName) and (StrPas(iServerName) <> '') then
Params.Values['SERVER NAME'] := StrPas(iServerName);
if Assigned(iDatabaseName) and (StrPas(iDatabaseName) <> '') then
Params.Values['DATABASE NAME'] := StrPas(iDatabaseName);
Params.Values['USER NAME'] := StrPas(iUserName);
Params.Values['PASSWORD'] := StrPas(iOldPassword);
LoginPrompt := False;
Connected := True;
end;
{ Create a query to run the system procedure with }
TempQuery := TQuery.Create(nil);
with TempQuery do
begin
try
DatabaseName := TempDatabase.DatabaseName;
{ Change the password in the RDBMS and set date of change }
SQL.Add(Format('execute ChangePassword %s, %s, %s',
[StrPas(iUserName),
StrPas(iOldPassword),
StrPas(iNewPassword)]));
try
ExecSQL;
except
raise EErrorChangingPassword.Create('');
end;
finally
Free;
end;
end;
finally
TempDatabase.Free;
end;
except
on ESamePassword do
begin
Result := cpSamePassword;
StrPCopy(oErrMsg, 'New password cannot be the same as the old password');
end;
on EErrorChangingPassword do
begin
Result := cpErrorChangingPassword;
StrPCopy(oErrMsg, 'Error changing password');
end;
on E: Exception do
begin
Result := cpUnknown;
StrPCopy(oErrMsg, E.Message);
end;
end;
end;
end.